﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using SklepISI.Core.Models;

namespace SklepISI.Core
{
    public class Bootstrapper
    {
        public static void Initialize()
        {
            AutoMapInitialize();
        }
        private  static void AutoMapInitialize()
        {
            Mapper.CreateMap<CategoryModel, Category>();
            Mapper.CreateMap<Category, CategoryModel>();

            Mapper.CreateMap<Role, RoleModel>();
            Mapper.CreateMap<RoleModel, Role>();

            Mapper.CreateMap<User, UserModel>();
            Mapper.CreateMap<UserModel, User>();

            Mapper.CreateMap<OrderStatus, OrderStatusModel>();
            Mapper.CreateMap<OrderStatusModel, OrderStatus>();


            Mapper.CreateMap<ProductModel, Product>()
                .ForMember(x => x.ID, y => y.MapFrom(z => z.ProductId));

            Mapper.CreateMap<Product, ProductModel>()
                .ForMember(x=>x.ProductId, y=>y.MapFrom(z=>z.ID));
            

            Mapper.CreateMap<OrderContent, OrderContentModel>();

            Mapper.CreateMap<OrderContentModel, OrderContent>();


            Mapper.CreateMap<Order, OrderModel>()
                .ForMember(dest => dest.Products, opts => opts.MapFrom(src => src.OrderContents))
                .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.OrderStatus));

            Mapper.CreateMap<OrderModel, Order>()
                .ForMember(dest => dest.OrderContents, opts => opts.MapFrom(src => src.Products))
                .ForMember(dest => dest.OrderStatus, opts => opts.MapFrom(src => src.Status));

            



        }
    }
}
